<template>
  <div class="address_manage">
   

    <ul class="address_main">
      <li v-for="(item,index) in list" v-if="item.is_default == 1">
        <div class="address_part1 flex">
          <p class="address_name">{{item.user_name}}</p>
          <p class="address_phone">{{item.user_mobile}}</p>
          <div class="address_change" @click="toAddressAdd(index)">编辑</div>
        </div>
        <div class="address_part2 flex">
          <div class="address_choose">默认</div>
          <!-- <div class="address_location">{{item.addr}}{{item.addr_detail}}</div> -->
          <div class="address_location">
            <p>{{item.addr}}</p>
            <p>{{item.addr_detail}}</p>
          </div>
          <div class="address_detele" @click="toDelete(item.id)">删除</div>
        </div>
      </li>
      <li v-for="(item,index) in list" v-if="item.is_default == 0">
        <div class="address_part1 flex">
          <p class="address_name">{{item.user_name}}</p>
          <p class="address_phone">{{item.user_mobile}}</p>
          <div class="address_change" @click="toAddressAdd(index)">编辑</div>
        </div>
        <div class="address_part2 flex">
          <div class="address_chooseNo"></div>
          <!-- <div class="address_location">{{item.addr}}{{item.addr_detail}}</div> -->
          <div class="address_location">
            <p>{{item.addr}}</p>
            <p>{{item.addr_detail}}</p>
          </div>
          <div class="address_detele" @click="toDelete(item.id)">删除</div>
        </div>
      </li>
    </ul>
     <div class="address_add" @click="toAddressAdd()">
      新增地址
    </div>
  </div>
</template>


<script>
import axios from 'axios'
import global from '../../../utils/global'
import store from '../../../utils/store'
export default {
  inject: ['reload'],
  name: 'address_manage',
  data () {
    return {
      // pick: '1',
      list:  [
        // {
        //   id: '1',
        //   name: '王卫',
        //   phone: '13812086937',
        //   address: '江苏省无锡市滨湖区楝泽路山水科教园17号楼地下2楼',
        // },
        // {
        //   id: '2',
        //   name: '郭郭',
        //   phone: '13812086937',
        //   address: '江苏省无锡市滨湖区楝泽路山水科教园17号楼地下2楼',
        // },
      ],
    }
  },
  mounted() {
    this.getInfo();
    this.$root.share();
  },
  methods: {
    toAddressAdd(index){
      var id = this.list[index];
      this.$router.push({
        // path:'/addressadd'
        name: 'addressAdd',
        params: {
          id: id
        }
      })
    },
    getInfo(index){
      var that = this;
      axios.get(global.api.address.myAddress,{
        params: {
          uuid: localStorage.getItem('carWashUuid'),
        }
      })
      .then(function(res){
        console.log("then");
        console.log(res);
        that.list = res.data.data;
      })
      .catch(function(res){
        console.log("catch");
        console.log(res);
      })
    },
    toDelete(index){
      console.log(index);
      console.log(global.api.address.detele);
      var that = this;
      axios.get(global.api.address.detele,{
        params: {
          uuid: localStorage.getItem('carWashUuid'),
          id: index
        }
      })
      .then(function(res){
        console.log("then");
        console.log(res);
        if (res.data.code == 0) {
          // that.getInfo()
          location.reload();
          // that.reload()
        }
      })
      .catch(function(res){
        console.log("catch");
        console.log(res);
      })
    },
  }
}
</script>

<style scoped>
  .address_add{
     margin: 3rem auto;
    line-height: 2.3rem;
    text-align: right;
    background-color: #2ecc80;
    width: 60%;
    text-align: center;
    border-radius: 5rem;
  }
  .address_main{}
  .address_main li {
    position: relative;
    padding: 0 0.5rem;
    border-bottom: 1px solid #B3B3B4;
  }
  .address_part1{
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0 0.5rem;
  }
  .address_part2{
    /*position: relative;*/
    padding: 0 0 0.5rem 0;
    justify-content: space-between;
    align-items: center;
  }
  .address_name{
    width: 3.5rem;
    font-size: 1rem;
    text-align: left;
    /*margin-left: 0.5rem;*/
  }
  .address_phone{
    font-size: 0.9rem;
    flex: 1;
    text-align: left;
  }
  .address_choose{
    /*position: absolute;
    left: 0.55rem;
    top: 0;*/
    width: 2.4rem;
    height: 1.4rem;
    line-height: 1.4rem;
    background-color: #2ecc80;
    color: #fff;
    font-size: 0.85rem;
    margin-right: 1.1rem;
  }
  .address_chooseNo{
    width: 3.5rem;
    height: 1.4rem;
    line-height: 1.4rem;
  }
  .address_location{
    /*max-width: 70%;*/
    /*padding: 0 3rem 0 3.5rem;*/
    flex: 1;
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.1rem;
  }
  .address_change{
    /*position: absolute;
    top: 0.7rem;
    right: 0;*/
    width: 3rem;
    height: 1.5rem;
    line-height: 1.5rem;
    font-size: 0.9rem;
    border-left: 1px solid #B3B3B4;
  }
  .address_detele{
    /*position: absolute;
    top: 3rem;
    right: 0;*/
    width: 3rem;
    height: 1.5rem;
    line-height: 1.5rem;
    font-size: 0.9rem;
    border-left: 1px solid #B3B3B4;
  }
</style>
<style>
  ul,li,div,a,p,span{
    margin: 0;
    padding: 0;
  }
  li{
    list-style: none;
  }
  .flex{
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
  }
</style>
